#include "ShaderMap.h"
#include "RHIShader.h"

ShaderMap::ShaderMap()
{
}

ShaderMap::~ShaderMap()
{
	std::unordered_map<std::string, RHIShader*>::iterator ownIt = mOwnMap.begin();
	while (ownIt != mOwnMap.end())
	{
		delete ownIt->second;
		++ownIt;
	}
	mOwnMap.clear();

	std::unordered_map<std::string, RHIShader*>::iterator delayIt = mDelayMap.begin();
	while (delayIt != mDelayMap.end())
	{
		delete delayIt->second;
		++delayIt;
	}
	mDelayMap.clear();
}


RHIShader* ShaderMap::GetShader(const std::string name) const
{
	if (mOwnMap.find(name) != mOwnMap.end())
	{
		return mOwnMap.find(name)->second;
	}
	assert(0);
	return nullptr;
}

void ShaderMap::CompileShader()
{
	std::unordered_map<std::string, RHIShader*>::iterator delayIt = mDelayMap.begin();
	while (delayIt != mDelayMap.end())
	{
		delayIt->second->CompileShader();
		mOwnMap.insert({ delayIt->first, delayIt->second });
		++delayIt;
	}
	mDelayMap.clear();
}
